﻿using System.Collections.Generic;
using System.Linq;

namespace Borg.Framework
{
    public class DependentPlugStartup : PlugStartup<DependentPlugAttribute>
    {
        private static readonly Dictionary<PlugInfo, DependentPlug> Data =
            new Dictionary<PlugInfo, DependentPlug>();

        public override void PlugCreated(PlugInfo plug, DependentPlugAttribute attr)
        {
            var list = new List<SlotInfo>();

            if (attr.Slots != null)
                list.AddRange(attr.Slots.Select(slot => plug.ExtensionInfo.SlotInfos[slot]));
            else
                list.Add(plug.ExtensionInfo.SlotInfos[attr.Slot]);

            Data[plug] = new DependentPlug(plug, list.ToArray());
        }

        public override void PlugReleased(PlugInfo plug, DependentPlugAttribute attr)
        {
            Data.Remove(plug);
        }

        public override void Register(ExtensionTypeInfo extType)
        { }

        public override void Unregister(ExtensionTypeInfo extType)
        { }
    }
}

